<template>
  <el-table v-loading="loading" :data="list" border fit highlight-current-row style="width: 800px;margin-top: 10px">
    <el-table-column align="center" width="60px" label="序号">
      <template slot-scope="scope">
        <span>{{ scope.row.num }}</span>
      </template>
    </el-table-column>
    <el-table-column align="center" width="140px" label="加入时间">
      <template slot-scope="scope">
        <span>{{ scope.row.createdAt | parseTime('{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
    <el-table-column align="center" width="120px" label="名称">
      <template slot-scope="scope">
        <span>{{ scope.row.name }}</span>
      </template>
    </el-table-column>
    <el-table-column align="center" width="100px" label="头像">
      <template slot-scope="scope">
        <img :width="40" :height="40" :src="'http://asset.u-link.club/'+scope.row.avatar" class="avatar" alt="">
      </template>
    </el-table-column>
    <el-table-column align="center" width="140px" label="账号">
      <template slot-scope="scope">
        <span>{{ scope.row.account }}</span>
      </template>
    </el-table-column>
    <el-table-column align="center" width="auto" label="操作">
      <template slot-scope="scope">
        <el-button type="primary" size="small" @click="edit(scope.row)">详情</el-button>
        <el-button type="danger" size="small" @click="del(scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { deleteTeacher } from '../../../api/teacher'

export default {
  name: 'TeacherTable',
  props: {
    list: {
      type: Array,
      required: true
    },
    loading: {
      type: Boolean
    }
  },
  data() {
    return {

    }
  },
  methods: {
    edit(item) {
      this.$emit('edit', item)
    },
    del(item) {
      this.$confirm('删除后该教师账号将无法登陆, 是否继续?', '删除提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteTeacher(item.id).then(() => {
          this.$SUCCESS('删除教师账号成功')
          this.$reload()
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>
.avatar{
    border-radius: 6px;
}
.el-table .cell{
    line-height: 0;
}
</style>
